@extends('Admin.layout.layout')
@section('title','用户管理')
@section('con')


    <div id="page-wrapper">
            <div class="row">
                <div class="col-lg-12">
                   
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
            <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                          <h2 class="page-header">用户添加</h2>
                        </div>
                        @if (count($errors) > 0)
                            <div class="alert alert-danger">
                                <ul>
                                    @foreach ($errors->all() as $error)
                                        <li>{{ $error }}</li>
                                    @endforeach
                                </ul>
                            </div>
                        @endif
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-6 col-lg-offset-3">
                                    <form role="form" id="myform" action="{{url('/Admin/user/insert')}}" method="post" enctype="multipart/form-data">
                                  
                                        <div class="form-group" id="dataTables-example_length">
                                         <label>权限: 
                                            <select name="auth" aria-controls="dataTables-example" class="form-control input-sm">
                                                <option value="0" @if(!empty($list['num']) && $list['num'] == 0 ){ selected } @endif)>超级管理员</option>
                                                <option value="1" @if(!empty($list['num']) && $list['num'] == 1 ){ selected } @endif)>普通员工</option>
                                                <option value="2" @if(!empty($list['num']) && $list['num'] == 2 ){ selected } @endif)>普通会员</option>
                                                
                                            </select></label>
                                        </div>
                                     
                                        <div class="form-group">
                                            <label>用户名:</label>
                                            <input name="uname" value="{{old('uname')}}" class="form-control">
                                            <div id="nameinfo" style="display:none"></div>
                                        </div>
                                        <div class="form-group">
                                            <label>密码:</label>
                                            <input name="upwd" value="{{old('upwd')}}" type="password" class="form-control">
                                            <div id="pass" style="display:none"></div>
                                        </div>

                                        <div class="form-group">
                                            <label>邮箱:</label>
                                            <input name="email" value="{{old('email')}}" class="form-control">
                                            <div id="word" style="display:none"></div>
                                        </div>

                                        <div class="form-group">
                                            <label>手机号:</label>
                                            <input name="tel" value="{{old('tel')}}" class="form-control">
                                            <div id="mobile" style="display:none"></div>
                                        </div>
                                        <div class="form-group">
                                            <label>头像:</label>
                                            <input type="file" name="uface">
                                        </div>
                                        {{csrf_field()}}
                                       
                                        
                                        <button class="btn btn-primary" type="submit">添加</button>
                                        <button class="btn btn-danger" type="reset">重置</button>
                                    </form>
                                </div>
                                <!-- /.col-lg-6 (nested) -->
                              
                                <!-- /.col-lg-6 (nested) -->
                            </div>
                            <!-- /.row (nested) -->
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
            </div>
        </div>
@endsection
@section('js')
     <script type="text/javascript">
      //获取表单对象
         var myform = document.getElementById('myform');
       
        //获取div元素
         var nameinfo = document.getElementById('nameinfo');
         var pass = document.getElementById('pass');
         var word = document.getElementById('word');
         var mobile = document.getElementById('mobile');
         
     
         var CUSER = false;
         var CPASS = false;
         var CEMAIL = false;
         var CPHONE = false;
        //绑定表单事件
        $('form').submit(function(){
            //触发所有的丧失焦点事件
            $('input').trigger('blur');
            //判断是否全部成功
            if(CUSER && CPASS && CPHONE && CEMAIL){
                return true;
            }

            return false;
        })
        

            
        //获取表单用户名丧失焦点事件
        myform.uname.onblur = function()
        {
          
                //获取输入的内容
                var v = this.value;
                var reg = /^\w{6,18}$/;
                if(reg.test(v)){
                
                   nameinfo.style.display = 'none';
                   this.style.border = '#c6c6c6 1px solid'; 
                   CUSER = true;
                }else{
                   
                   this.style.border = 'red 1px solid'; 
                   nameinfo.innerHTML = '输入的用户名不符合要求';
                   nameinfo.style.color = 'red';
                   nameinfo.style.display = 'block';
                    CUSER = false;
                }
        }

        //绑定表单密码的失去焦点事件
         myform.upwd.onblur = function()
        {
           
                //获取输入的内容
                var v = this.value;
                var reg = /^\w{6,18}$/;
                if(reg.test(v)){
                   pass.style.display = 'none';
                   this.style.border = '#c6c6c6 1px solid';
                    CPASS = true;
                }else{
                   this.style.border = 'red 1px solid'; 
                   pass.innerHTML = '输入的密码不符合要求';
                   pass.style.color = 'red';
                   pass.style.display = 'block';
                 CPASS = false;
                }
        }

        
        //绑定表单手机号的失去焦点事件
        myform.tel.onblur = function()
        {
          
                //获取输入的内容
                var v = this.value;
                var reg = /^1[34578]\d{9}$/;
                if(reg.test(v)){
                   mobile.style.display = 'none';
                   this.style.border = '#c6c6c6 1px solid'; 
                   CPHONE = true;
                }else{
                   this.style.border = 'red 1px solid'; 
                   mobile.innerHTML = '输入的手机号不符合要求';
                   mobile.style.color = 'red';
                   mobile.style.display = 'block';
                   CPHONE = false;
                }
        }

        //绑定表单邮箱的失去焦点事件
        myform.email.onblur = function()
        {
          
                //获取输入的内容
                var v = this.value;
                var reg = /^\w+@\w+\.(com|cn|com\.cn|net)$/;
                if(reg.test(v)){
                   word.style.display = 'none';
                   this.style.border = '#c6c6c6 1px solid'; 
                   CEMAIL = true;
                }else{
                   this.style.border = 'red 1px solid'; 
                   word.innerHTML = '输入的邮箱不符合要求';
                   word.style.color = 'red';
                   word.style.display = 'block';
                   CEMAIL = false;
                }
        }

       
     </script>

@endsection
